//
//  CZStatusNormalCell.swift
//  GZWeibo007
//
//  Created by Apple on 15/12/21.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
import SDWebImage
/// 原创cell
class CZStatusNormalCell: CZStatusCell {
    
    override var status: CZStatus?{
        didSet{
            
            switch picCount{
                
            case 0 : pictureView.snp_remakeConstraints(closure: { (make) -> Void in
                make.leading.equalTo(contentView)
                make.top.equalTo(contentLabel.snp_bottom).offset(8)
                make.height.equalTo(0)
            })
            case 1 :
                // 特殊处理图片
                
                var W = 0.0
                var H = 0.0
                
                let url = status!.pictureURLs![0]
                if let image = SDImageCache.sharedImageCache().imageFromDiskCacheForKey(url.absoluteString) {
                    // 有图片,设置itemSize为图片的大小
                    var size = image.size
                    // 判断,图片太小
                    if size.width < 40 {
                        size.width = 40
                    } else if size.width > UIScreen.mainScreen().bounds.width * 0.5 {
                        size.width = UIScreen.mainScreen().bounds.width * 0.5
                    }
                    
                    W = (Double)(size.width)
                    H = (Double)(size.height)
                    
                }
                pictureView.snp_remakeConstraints(closure: { (make) -> Void in
                    make.leading.equalTo(contentView).offset(8)
                    make.top.equalTo(contentLabel.snp_bottom).offset(8)
                    make.height.equalTo(W).priorityHigh()
                    make.width.equalTo(H).priorityHigh()
                })
            case 4 : pictureView.snp_remakeConstraints(closure: { (make) -> Void in
                make.leading.equalTo(contentView).offset(8)
                make.top.equalTo(contentLabel.snp_bottom).offset(8)
                make.width.equalTo(190).priorityHigh()
                make.height.equalTo(190).priorityHigh()
            })
            case 2,3 : pictureView.snp_remakeConstraints(closure: { (make) -> Void in
                make.leading.equalTo(contentView).offset(8)
                make.trailing.equalTo(contentView)
                make.top.equalTo(contentLabel.snp_bottom).offset(8)
                make.height.equalTo(90).priorityHigh()
            })
                
            case 5,6 : pictureView.snp_remakeConstraints(closure: { (make) -> Void in
                make.leading.equalTo(contentView).offset(8)
                make.trailing.equalTo(contentView)
                make.top.equalTo(contentLabel.snp_bottom).offset(8)
                make.height.equalTo(180).priorityHigh()
            })
            default : pictureView.snp_remakeConstraints(closure: { (make) -> Void in
                make.leading.equalTo(contentView).offset(8)
                make.trailing.equalTo(contentView)
                make.top.equalTo(contentLabel.snp_bottom).offset(8)
                make.height.equalTo(290).priorityHigh()
            })
            }
            
        }
        
    }
    
    /// 覆盖父类的方法,添加配图的约束
    override func preapreUI() {
        super.preapreUI()
        
    }
}